package org.senseframework.support.example.hibernate.domain;


import org.hibernate.annotations.GenericGenerator;
import org.senseframework.support.core.spring.SpringApplicationContext;
import org.senseframework.support.orm.hibernate.BasicDomain;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.orm.hibernate3.HibernateOperations;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

/**
 * Created by lanjian
 */
@MappedSuperclass
@Configurable(autowire = Autowire.BY_TYPE)
public abstract class Basic<T extends Basic> extends BasicDomain<T, String> {

    @Id
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @GeneratedValue(generator = "uuid")
    @Column(name = "id", unique = true, nullable = false)
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    protected HibernateOperations getDatabaseSession() {
        return SpringApplicationContext.getBean("hibernateTemplate");
    }


}
